import React, {
  Component,
  Fragment
} from 'react';
import PropTypes from 'prop-types'
class TodoItem extends Component {
  constructor(props) {
    super(props)
    this.handleClick = this.handleClick.bind(this)//节省性能
    this.state = {}
  }
  static defaultProps = {
    name: 'item',
    age:18
  }
  static propTypes = {
    value: PropTypes.string.isRequired,
    index: PropTypes.number,
    deleteItem: PropTypes.func
  }
  render() {
    const {value} = this.props;
    return ( < Fragment > <li onClick={this.handleClick}>{value}</li></Fragment > )
  }

  handleClick(){
    const {deleteItem,index} = this.props;
    console.log('删除成功'+index)
    deleteItem(this.props.index)
  }
  }

  export default TodoItem;
